package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.ruoyi.web.controller.tool.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhuanjiaRenkouhechaPici;
import com.ruoyi.system.service.IZhuanjiaRenkouhechaPiciService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-07-31
 */
@Controller
@RequestMapping("/system/renkouhechapici")
public class ZhuanjiaRenkouhechaPiciController extends BaseController
{
    private String prefix = "system/pici";

    @Autowired
    private IZhuanjiaRenkouhechaPiciService zhuanjiaRenkouhechaPiciService;

    @RequiresPermissions("system:pici:view")
    @GetMapping()
    public String pici()
    {
        return prefix + "/pici";
    }

    /**
     * 查询【请填写功能名称】列表
     */
//    @RequiresPermissions("system:pici:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhuanjiaRenkouhechaPici zhuanjiaRenkouhechaPici)
    {
        startPage();
        List<ZhuanjiaRenkouhechaPici> list = zhuanjiaRenkouhechaPiciService.selectZhuanjiaRenkouhechaPiciList(zhuanjiaRenkouhechaPici);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:pici:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhuanjiaRenkouhechaPici zhuanjiaRenkouhechaPici)
    {
        List<ZhuanjiaRenkouhechaPici> list = zhuanjiaRenkouhechaPiciService.selectZhuanjiaRenkouhechaPiciList(zhuanjiaRenkouhechaPici);
        ExcelUtil<ZhuanjiaRenkouhechaPici> util = new ExcelUtil<ZhuanjiaRenkouhechaPici>(ZhuanjiaRenkouhechaPici.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
//    @RequiresPermissions("system:pici:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhuanjiaRenkouhechaPici zhuanjiaRenkouhechaPici)
    {
        zhuanjiaRenkouhechaPici.setId(UUID.randomUUID().toString());
        zhuanjiaRenkouhechaPici.setKaishishijian(new Date());
        zhuanjiaRenkouhechaPici.setRenshu((long)0);
        zhuanjiaRenkouhechaPici.setWeihecha((long)0);
        zhuanjiaRenkouhechaPici.setYihecha((long)0);
        zhuanjiaRenkouhechaPici.setIsvalid((long)1);
        return toAjax(zhuanjiaRenkouhechaPiciService.insertZhuanjiaRenkouhechaPici(zhuanjiaRenkouhechaPici));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:pici:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZhuanjiaRenkouhechaPici zhuanjiaRenkouhechaPici = zhuanjiaRenkouhechaPiciService.selectZhuanjiaRenkouhechaPiciById(id);
        mmap.put("zhuanjiaRenkouhechaPici", zhuanjiaRenkouhechaPici);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
//    @RequiresPermissions("system:pici:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhuanjiaRenkouhechaPici zhuanjiaRenkouhechaPici)
    {
        return toAjax(zhuanjiaRenkouhechaPiciService.updateZhuanjiaRenkouhechaPici(zhuanjiaRenkouhechaPici));
    }

    @PostMapping("/findone")
    @ResponseBody
    public JsonResult<?> findone(@RequestParam("id")String ppId)
    {
        ZhuanjiaRenkouhechaPici mmPici = zhuanjiaRenkouhechaPiciService.selectZhuanjiaRenkouhechaPiciById(ppId);
        if (mmPici==null){
            return  JsonResult.getErrorResult("该批次查询失败");
        }

        return JsonResult.getSuccessResult(mmPici);
    }

    /**
     * 删除【请填写功能名称】
     */
//    @RequiresPermissions("system:pici:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zhuanjiaRenkouhechaPiciService.deleteZhuanjiaRenkouhechaPiciByIds(ids));
    }
}
